package com.shujia.util

import org.apache.spark.SparkContext
import org.apache.spark.sql.SparkSession
import org.apache.spark.streaming.{Durations, StreamingContext}

abstract class SparkStreamTool {
  var spark: SparkSession = _
  var sc: SparkContext = _
  var ssc: StreamingContext = _

  def main(args: Array[String]): Unit = {

    //1、创建spark 环境
    spark = SparkSession
      .builder()
      .master("local[4]")
      .appName("RealTimeCardDayFlow")
      .getOrCreate()

    sc = spark.sparkContext


    //创建spark streaming 环境
    ssc = new StreamingContext(sc, Durations.seconds(5))

    //设置checkpoint
    ssc.checkpoint("data/checkpoint")

    this.run(args)

    ssc.start()
    ssc.awaitTermination()
    ssc.stop()

  }

  def run(args: Array[String])

}
